package com.rzrk.centerlogserver.mq;

import javax.annotation.Resource;

import org.apache.commons.lang3.StringUtils;
import org.springframework.data.mongodb.core.MongoOperations;
import org.springframework.stereotype.Component;

import com.alibaba.fastjson.JSON;
import com.rzrk.centerlog.entity.NormalLog;
import com.rzrk.centerlog.entity.OperateLog;

@Component
public class LogStoreStrategyOperate implements LogStoreStrategy{
	@Resource
	MongoOperations mongoOperations;

	@Override
	public boolean save(String msg) {
		if(StringUtils.startsWith(msg, "operateLog")){
			String[] msgArr = msg.split("\\s",2);
			if(msgArr.length>1){
				String dataStr = msgArr[1];
				OperateLog operateLog = JSON.parseObject(dataStr, OperateLog.class);
				mongoOperations.save(operateLog);
				return true;
			}
		}
		return false;
	}

}
